package com.tusuo.stds.util;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

import com.scwang.smartrefresh.layout.api.RefreshHeader;
import com.scwang.smartrefresh.layout.api.RefreshKernel;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.RefreshState;
import com.scwang.smartrefresh.layout.constant.SpinnerStyle;
import com.tusuo.stds.R;

/**
 * Created by developer on 17-8-30.
 */

public class MyClassicsHeader extends LinearLayout implements RefreshHeader {

    private OnHeaderScrollListener mOnHeaderScrollListener;
    private boolean isJumped = false;


    public MyClassicsHeader(Context context) {
        super(context);
        initView(context);

    }

    public MyClassicsHeader(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);

    }

    void initView(Context context) {
        View view = View.inflate(context, R.layout.refresh_header,null);
        addView(view);
    }

    @Override
    public void onPullingDown(float percent, int offset, int headerHeight, int extendHeight) {

    }

    @Override
    public void onReleasing(float percent, int offset, int headerHeight, int extendHeight) {
        if (!isJumped) {
            isJumped = mOnHeaderScrollListener.onHeaderScroll(percent);
        }
        if (percent == 0) {
            isJumped = false;
        }
    }

    @NonNull
    @Override
    public View getView() {
        return this;
    }

    @Override
    public SpinnerStyle getSpinnerStyle() {
        return SpinnerStyle.Translate;
    }

    @Override
    public void setPrimaryColors(int... colors) {

    }

    @Override
    public void onInitialized(RefreshKernel kernel, int height, int extendHeight) {

    }

    @Override
    public void onStartAnimator(RefreshLayout layout, int height, int extendHeight) {

    }

    @Override
    public int onFinish(RefreshLayout layout, boolean success) {
        return 0;
    }

    @Override
    public void onStateChanged(RefreshLayout refreshLayout, RefreshState oldState, RefreshState newState) {

    }

    public void setOnHeaderScrollListener(OnHeaderScrollListener onHeaderScrollListener) {
        mOnHeaderScrollListener = onHeaderScrollListener;
    }

    public interface OnHeaderScrollListener {
        boolean onHeaderScroll(float percent);
    }

}
